import datetime
import time

from common.logOutput import info
from common.yamlLoad import YamlRead
from business_common.requestFunc import BusinessRequest

env_config = YamlRead().env_config()
api_config = YamlRead().api_config()

class DataCreate:
    host = env_config['host']


    def create_note(self, num, sid, user_id, group_id=None, remind_time=None):
        """新建便签主体"""
        note_list = []
        # for 循环来控制要创建的便签个数
        for i in range(num):
            note_id = str(int(time.time() * 1000))
            create_note_info_url = self.host + api_config['create_noteInfo']['path']
            # 根据body中参数来区分创建的便签类型
            if remind_time: # 日历下便签
                body = {
                    "noteId": note_id,
                    "remindTime": remind_time,
                    "remindType":0,
                    "star": 0
                }
            elif group_id: # 分组下便签
                body = {
                    "noteId": note_id,
                    "groupId":group_id,
                    "star": 0
                }
            else: # 普通首页便签
                body = {
                    "noteId": note_id,
                    "star": 0
                }
            info('[step] 开始新建便签主体')
            BusinessRequest.post(create_note_info_url, sid, user_id, body=body,)

            """新建便签内容"""
            create_note_content_url = self.host + api_config['create_noteContent']['path']
            body = {
                "noteId": note_id,
                "title": None,
                "summary": "5qDHxlg68H8nollMqchfEA==",
                "body": "NOWeKsxy5983z4KtAACa2Bg2J08jH93dOGuPw4pU0e4=",
                "localContentVersion": 1,
                "BodyType": 0
            }
            BusinessRequest.post(create_note_content_url, sid=sid, user_id=user_id, body=body)
            note_list.append(body)
        return note_list

    def create_group(self, sid, user_id):
        """新建分组"""
        group_list = []
        group_id = str(int(time.time()))
        group_name = f'0group_{int(time.time())}'
        body = {
            'groupId': group_id,
            'groupName': group_name,
            'order': 0
        }
        create_group_url = self.host + api_config['create_group']['path']
        BusinessRequest.post(create_group_url, sid, user_id, body=body)
        group_list.append(body)
        return group_list


if __name__ == '__main__':
    DataCreate().create_note(1,env_config['wps_sid'], env_config['user_id'])


